package com.franklin.icharm.service;

import static java.util.UUID.fromString;

import java.util.Timer;
import java.util.UUID;

public class Watch {
	public final static UUID 
	UUID_IRT_SERV = fromString("f000aa00-0451-4000-b000-000000000000"),
	UUID_IRT_DATA = fromString("f000aa01-0451-4000-b000-000000000000"),
	UUID_IRT_CONF = fromString("f000aa02-0451-4000-b000-000000000000"), // 0: disable, 1: enable
	UUID_IRT_PERI = fromString("f000aa03-0451-4000-b000-000000000000"), // Period in tens of milliseconds

	UUID_ACC_SERV = fromString("f000aa10-0451-4000-b000-000000000000"),
	UUID_ACC_DATA = fromString("f000aa11-0451-4000-b000-000000000000"),
	UUID_ACC_CONF = fromString("f000aa12-0451-4000-b000-000000000000"), // 0: disable, 1: enable
	UUID_ACC_PERI = fromString("f000aa13-0451-4000-b000-000000000000"), // Period in tens of milliseconds

	UUID_HUM_SERV = fromString("f000aa20-0451-4000-b000-000000000000"),
	UUID_HUM_DATA = fromString("f000aa21-0451-4000-b000-000000000000"),
	UUID_HUM_CONF = fromString("f000aa22-0451-4000-b000-000000000000"), // 0: disable, 1: enable
	UUID_HUM_PERI = fromString("f000aa23-0451-4000-b000-000000000000"), // Period in tens of milliseconds

	UUID_MAG_SERV = fromString("f000aa30-0451-4000-b000-000000000000"),
	UUID_MAG_DATA = fromString("f000aa31-0451-4000-b000-000000000000"),
	UUID_MAG_CONF = fromString("f000aa32-0451-4000-b000-000000000000"), // 0: disable, 1: enable
	UUID_MAG_PERI = fromString("f000aa33-0451-4000-b000-000000000000"), // Period in tens of milliseconds

	UUID_BAR_SERV = fromString("f000aa40-0451-4000-b000-000000000000"), 
	UUID_BAR_DATA = fromString("f000aa41-0451-4000-b000-000000000000"),
	UUID_BAR_CONF = fromString("f000aa42-0451-4000-b000-000000000000"), // 0: disable, 1: enable
	UUID_BAR_CALI = fromString("f000aa43-0451-4000-b000-000000000000"), // Calibration characteristic
	UUID_BAR_PERI = fromString("f000aa44-0451-4000-b000-000000000000"), // Period in tens of milliseconds

	UUID_GYR_SERV = fromString("f000aa50-0451-4000-b000-000000000000"), 
	UUID_GYR_DATA = fromString("f000aa51-0451-4000-b000-000000000000"),
	UUID_GYR_CONF = fromString("f000aa52-0451-4000-b000-000000000000"), // 0: disable, bit 0: enable x, bit 1: enable y, bit 2: enable z
	UUID_GYR_PERI = fromString("f000aa53-0451-4000-b000-000000000000"), // Period in tens of milliseconds

	UUID_ALE_SERV = fromString("00001802-0000-1000-8000-00805f9b34fb"), 
	UUID_ALE_DATA = fromString("00002a06-0000-1000-8000-00805f9b34fb"), 

			UUID_LED_SERV = fromString("0000aa60-0000-1000-8000-00805f9b34fb"), 
			UUID_LED_DATA = fromString("0000aa61-0000-1000-8000-00805f9b34fb"),
					UUID_IKEY_SERV = fromString("0000ffe0-0000-1000-8000-00805f9b34fb"), 
					UUID_IKEY_DATA = fromString("0000ffe1-0000-1000-8000-00805f9b34fb"),

	UUID_KEY_SERV = fromString("0000fff0-0000-1000-8000-00805f9b34fb"), 
	UUID_KEY_DATA = fromString("0000fff1-0000-1000-8000-00805f9b34fb"),
	UUID_LCD_TXT = fromString("0000ffdc-0000-1000-8000-00805f9b34fb");
	

	


	public final static byte  CLED_RED =           (byte) 0xE0;
	public final static byte  CLED_ORANGE_RED =  (byte) 0xE4;
	public final static byte  CLED_ORANGE      = (byte) 0xEC;
	public final static byte  CLED_YELLOW      = (byte)0xFC;
	public final static byte  CLED_YELLOW_GREEN =(byte)0x7C;
	public final static byte  CLED_GREEN        =(byte)0x1C;
	public final static byte  CLED_CYAN         =(byte)0x1F;
	public final static byte  CLED_BLUE         =(byte)0x07;
	public final static byte  CLED_VIOLET       =(byte)0x63;
	public final static byte  CLED_MAGENTA      =(byte)0xE3;
	public final static byte  CLED_WHITE        =(byte)0xFF;
	public final static byte  CLED_BLACK        =(byte)0x00;

	public final static byte[] CALLER_VIP_LED = {CLED_WHITE, CLED_BLACK, CLED_WHITE , CLED_BLACK};

	public final static byte[] CALLER_GROUP1_LED = { CLED_RED, CLED_BLACK, CLED_BLACK , CLED_BLACK};
	public final static byte[] CALLER_GROUP2_LED = {CLED_ORANGE, CLED_BLACK, CLED_BLACK , CLED_BLACK};
	public final static byte[] CALLER_GROUP3_LED = { CLED_YELLOW, CLED_BLACK, CLED_BLACK , CLED_BLACK};
	public final static byte[] CALLER_GROUP4_LED = { CLED_GREEN, CLED_BLACK, CLED_BLACK , CLED_BLACK};
	public final static byte[] CALLER_UNGROUP_LED = { CLED_CYAN, CLED_BLACK, CLED_BLACK , CLED_BLACK};

	public final static byte[] APP_GROUP1_LED = { CLED_RED, CLED_BLACK, CLED_WHITE , CLED_BLACK};
	public final static byte[] APP_GROUP2_LED = { CLED_ORANGE, CLED_BLACK, CLED_WHITE , CLED_BLACK};
	public final static byte[] APP_GROUP3_LED = { CLED_YELLOW, CLED_BLACK, CLED_WHITE , CLED_BLACK};
	public final static byte[] APP_GROUP4_LED = { CLED_GREEN, CLED_BLACK, CLED_WHITE , CLED_BLACK};


	public final static byte[] TOUCH_X1_LED = { CLED_RED, CLED_RED, CLED_RED , CLED_RED};
	public final static byte[] TOUCH_X2_LED = { CLED_ORANGE, CLED_ORANGE, CLED_ORANGE , CLED_ORANGE};
	public final static byte[] TOUCH_X3_LED = { CLED_YELLOW, CLED_YELLOW, CLED_YELLOW , CLED_YELLOW};
	public final static byte[] TOUCH_X4_LED = { CLED_GREEN, CLED_GREEN, CLED_GREEN , CLED_GREEN};



	public final static byte[] TAKE_OFF_LED = { CLED_BLACK, CLED_BLACK, CLED_BLACK , CLED_BLACK};

	public final static byte[] TAKE_LOSTLINK_ON = { 0x04, 0x04, 0x04 , 0x01};
	public final static byte[] TAKE_LOSTLINK_OFF = { 0x04, 0x04, 0x04 , 0x00};
	
	public final static byte[][] TOUCH_GROUPS_LED = {TAKE_OFF_LED, TOUCH_X1_LED, TOUCH_X2_LED , TOUCH_X3_LED, TOUCH_X4_LED};
	public final static byte[][] APP_GROUPS_LED = {TAKE_OFF_LED, APP_GROUP1_LED, APP_GROUP2_LED , APP_GROUP3_LED, APP_GROUP4_LED};

	
	
	public final static byte KEYEVENT_MOVE_LR	= 0x01;
	public final static byte KEYEVENT_MOVE_RL	= 0x02;
	public final static byte KEYEVENT_PHOLD_L	= 0x03;
	public final static byte KEYEVENT_PHOLD_R	= 0x04;
	public final static byte KEYEVENT_REL_L	= 0x05;
	public final static byte KEYEVENT_REL_R	= 0x06;
	public final static byte KEYEVENT_PHOLD_LR	= 0x07;
	
	
	// Operation mode
	public static final int OPMODE_LOSSLINK = 0;
	public static final int OPMODE_SLEEP = 1;
	public static final int OPMODE_WAKEUP = 2;
	public static final int OPMODE_STANDBY = 3;
	public static final int OPMODE_TOUCH = 4;
	public static final int OPMODE_ALERT_CALLER = 5;
	public static final int OPMODE_ALERT_APP = 6;
	public static final int OPMODE_REJECT_CALL = 7;
	
	public static final String[] OPMODE_NAME ={
		"OPMODE_LOSSLINK" ,
		"OPMODE_SLEEP",
		"OPMODE_WAKEUP",
		"OPMODE_STANDBY",
		"OPMODE_APPS",
		"OPMODE_ALERT_CALLER",
		"OPMODE_ALERT_APP",
		"OPMODE_REJECT_CALL"
	};
	
	public Timer keyTimer ;
	private  int opmode = OPMODE_LOSSLINK;
	public int slideKeyCounter = 0;

	public int getOpmode() {
		return opmode;
	}

	public void setOpmode(int opmode) {
		this.opmode = opmode;
	}

	public void ClearKeyTimer()
	{
		if (keyTimer !=null)
		{
			keyTimer.cancel();
			keyTimer = null;
		}
	}
	

	public String toString()
	{
		String opname ;
		if (opmode < OPMODE_NAME.length)
			opname = OPMODE_NAME[opmode];
		else
			opname = "UNKNOWN";
		return String.format("state-> (%d) %s ", opmode , opname);
	}

}
